home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / chunkytools.e < prev    next >
Encoding:
Text File  |  1999-06-30  |  3.0 KB  |  168 lines

  1. /* ************* */
  2. /* chunkytools.e */
  3. /* ************* */
  4.  
  5.  
  6.  
  7. /*
  8.     WBBump - Bumpmapping on the Workbench!
  9.  
  10.     Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software Foundation,
  24.     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26.  
  27.  
  28.  
  29.  
  30. OPT MODULE
  31.  
  32.  
  33. MODULE    'graphics/gfx',
  34.         'graphics/rastport',
  35.  
  36.         'exec/memory'
  37.  
  38.  
  39.  
  40.  
  41. EXPORT PROC alloc_temprp(rp, width)
  42.     DEF    temprp=NIL:PTR TO rastport,
  43.         i
  44.  
  45.  
  46.     NEW temprp
  47.  
  48.     CopyMem(rp, temprp, SIZEOF rastport)
  49.  
  50.     temprp.layer := NIL
  51.  
  52.     temprp.bitmap := NewR(SIZEOF bitmap)
  53.  
  54.     temprp.bitmap.bytesperrow := Shl(Shr(width + 15, 4), 1)
  55.     temprp.bitmap.rows := 1
  56.     temprp.bitmap.flags := BMF_STANDARD
  57.     temprp.bitmap.depth := 8
  58.     FOR i := 0 TO 7
  59.         /* Under what circumstances can planes be allocated in FAST ??? */
  60.         temprp.bitmap.planes[i] := NewM(temprp.bitmap.bytesperrow, MEMF_CHIP)
  61.     ENDFOR
  62.     
  63. ENDPROC temprp
  64.  
  65.  
  66. EXPORT PROC free_temprp(temprp:PTR TO rastport)
  67.     DEF    i
  68.  
  69.     IF temprp
  70.         IF temprp.bitmap
  71.             FOR i := 0 TO 7
  72.                 IF temprp.bitmap.planes[i] THEN Dispose(temprp.bitmap.planes[i])
  73.             ENDFOR
  74.             Dispose(temprp.bitmap)
  75.         ENDIF
  76.         END temprp
  77.     ENDIF
  78. ENDPROC
  79.  
  80.  
  81.  
  82.  
  83. EXPORT PROC bitmap2chunky(bm:PTR TO bitmap, buf, x, y, w, h) HANDLE
  84.     DEF    rp=NIL:PTR TO rastport,
  85.         temprp
  86.  
  87.     NEW rp
  88.     InitRastPort(rp)
  89.     rp.bitmap := bm
  90.  
  91.     temprp := alloc_temprp(rp, w)
  92.  
  93.     rastport2chunky(rp, buf, x, y, w, h, temprp)
  94.  
  95. EXCEPT DO
  96.     IF temprp THEN free_temprp(temprp)
  97.     END rp
  98. ENDPROC
  99.  
  100.  
  101.  
  102. EXPORT PROC rastport2chunky(rp:PTR TO rastport, buf, x, y, w, h, temprp) HANDLE
  103.     DEF    tempbuf=NIL:PTR TO CHAR,
  104.         lineadr=0,
  105.         iy
  106.  
  107.     
  108.     tempbuf := NewR(w + 16)
  109.  
  110.  
  111.     lineadr := 0
  112.     FOR iy := 0 TO h-1
  113.         ReadPixelLine8(rp, x, y+iy, w, tempbuf, temprp)
  114.         CopyMem(tempbuf, buf + lineadr, w)
  115.         lineadr := lineadr + w
  116.     ENDFOR
  117.  
  118.  
  119. EXCEPT DO
  120.     IF tempbuf THEN Dispose(tempbuf)
  121.     ReThrow()
  122. ENDPROC
  123.  
  124.  
  125.  
  126.  
  127. EXPORT PROC chunky2bitmap(bm:PTR TO bitmap, buf, x, y, w, h) HANDLE
  128.     DEF    rp=NIL:PTR TO rastport,
  129.         temprp=NIL
  130.  
  131.     NEW rp
  132.     InitRastPort(rp)
  133.     rp.bitmap := bm
  134.  
  135.     temprp := alloc_temprp(rp, w)
  136.  
  137.     IF chunky2rastport(rp, buf, x, y, w, h, temprp) = FALSE THEN Raise(-1)
  138.  
  139. EXCEPT DO
  140.     IF temprp THEN free_temprp(temprp)
  141.     END rp
  142.     IF exception THEN RETURN FALSE
  143. ENDPROC TRUE
  144.  
  145.  
  146.  
  147.  
  148.  
  149. EXPORT PROC chunky2rastport(rp:PTR TO rastport, buf, x, y, w, h, temprp) HANDLE
  150.     DEF    lineadr=0,
  151.         iy
  152.  
  153.  
  154.     lineadr := 0
  155.     FOR iy := 0 TO h-1
  156.         WritePixelLine8(rp, x, y+iy, w, buf + lineadr, temprp)
  157.         lineadr := lineadr + w
  158.     ENDFOR
  159.  
  160.  
  161. EXCEPT DO
  162.     IF exception THEN RETURN FALSE
  163. ENDPROC TRUE
  164.  
  165.  
  166.  
  167.  
  168.